home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / s342q07.lha / netrcv.c < prev    next >
C/C++ Source or Header  |  1995-09-12  |  22KB  |  908 lines

  1. /*
  2. *       netrcv.c
  3. *
  4. *      Networking functions for reception.
  5. */
  6. /*
  7. *       history
  8. *
  9. * 86Aug20 HAW  History not maintained due to space problems.
  10. */
  11. #include "ctdl.h"
  12. /*
  13. *       Contents
  14. *
  15. * called()    Handle being called.
  16. * rcvStuff()    Manage receiving stuff.
  17. * netPwd()    Check password.
  18. * doResults()   Post-process results.
  19. * getId()     Get nodeId and nodeName from caller.
  20. * getNextCommand()  Get next command.
  21. * grabCommand()   Extract network cmds from buffer.
  22. * reply()     Sends a reply to caller.
  23. * reqReversal()   Handle role reversal.
  24. * reqCheckMail()    Check incoming mail.
  25. * targetCheck()   Check for existence of recipients.
  26. * CheckRecipient()  work fn for above.
  27. * doNetRooms()    Manage integrating incoming messages.
  28. * IntegrateRoom()   work fn for above.
  29. * ReadNetRoomFile() work fn for above.
  30. * getMail()   Handle incoming mail.
  31. * reqSendFile()   Receive a sent file.
  32. * netFileReq()    Senda a requested file.
  33. * netRRReq()    Handle room sharing.
  34. * recNetMessages()  Receive net messages.
  35. * UpdateRecoveryFile()  Updates the network recovery file.
  36. *   RoomRoutable()    Is this room routable?
  37. * IsRoomRoutable()  Is this room routable?
  38. * netMultiSend()    Send multiple files.
  39. * RecoverNetwork()  Recover from network disaster.
  40. */
  41. extern char logNetResults;
  42. char        netDebug = FALSE;
  43. char    processMail;
  44. char    PosId;
  45. char    *AssignAddress = NULL;
  46. #define RECOVERABLE 1
  47. extern char   *SR_Sent;
  48. extern FILE   *netLog, *netMisc;
  49. extern AN_UNSIGNED      RecBuf[];
  50. extern int    counter;
  51. extern int    callSlot;
  52. extern char   checkNegMail;
  53. extern char   inReceive;
  54. extern label    normed, callerName, callerId;
  55. extern char   RouteMailForHere;
  56. extern char   *LOC_NET, *NON_LOC_NET;
  57. char    normId(), getNetMessage();
  58. char    callOut();
  59. AN_UNSIGNED      inp();
  60. char *netRoomTemplate = "room%d.$$$";
  61. char *SharingRefusal[] =
  62.   {
  63.   "'%s' does not exist",
  64.   "'%s' is not a networking room",
  65.   "'%s' is not networking with you",
  66.   "No can do for '%s'",
  67.  
  68.   };
  69. extern char  RecMassTransfer;
  70. extern CONFIG    cfg;   /* Lots an lots of variables    */
  71. extern logBuffer logBuf;  /* Person buffer    */
  72. extern logBuffer logTmp;  /* Person buffer    */
  73. extern aRoom     roomBuf; /* Room buffer    */
  74. extern rTable    *roomTab;
  75. extern MessageBuffer   msgBuf;
  76. extern NetBuffer netBuf;
  77. extern NetTable  *netTab;
  78. extern int       thisNet;
  79. extern char      onConsole;
  80. extern char      loggedIn;  /* Is we logged in?   */
  81. extern char      outFlag; /* Output flag    */
  82. extern char      haveCarrier; /* Do we still got carrier?     */
  83. extern char      modStat; /* Needed so we don't die       */
  84. extern char      WCError;
  85. extern int       thisRoom;
  86. extern int       thisLog;
  87. extern char  *APPEND_TEXT, *WRITE_TEXT, *READ_TEXT;
  88. extern char  *R_SH_MARK, *NON_LOC_NET, *LOC_NET;
  89. extern long char_in, char_out, start_time;
  90.  
  91. /*
  92. * called()
  93. *
  94. * We've been called, so let's handle it.
  95. */
  96. void called()
  97.   {
  98.   ITL_InitCall();   /* Initialize the ITL layer */
  99.   memset(SR_Sent, 0, SHARED_ROOMS);
  100.   inReceive = TRUE;
  101.   RecMassTransfer = FALSE;
  102.   SpecialMessage("Status:Net Carrier");
  103.   if( logNetResults || netDebug )splitF(netLog, "Carrier %s\n", Current_Time());
  104.   processMail = checkNegMail = FALSE;
  105.   if (!called_stabilize())
  106.     {
  107.     if (cfg.BoolFlags.debug)splitF(netLog," Not Stabilized...\n");
  108.     return ;
  109.  
  110.     };
  111.   if( logNetResults )splitF(netLog, "Stabilized\n");
  112.   SpecialMessage("Status:Net Session");
  113.   char_in = char_out = 0;
  114.   start_time = Set_Timer(0);       /* initialize time of day */
  115.   getId();
  116.   if (!haveCarrier) return;
  117.   rcvStuff(FALSE);
  118.   if ( logNetResults )splitF(netLog, "Finished with %s @%s\n",  callerName, Current_Time());
  119.   Compute_Data(callerName);
  120.   pause(20);
  121.   killConnection();
  122.   doResults();
  123.   if( logNetResults )splitF(netLog, "\n");
  124.   SpecialMessage("Status:Net Completed");
  125.  
  126.   }
  127. /*
  128. * rcvStuff()
  129. *
  130. * This function manages receiving stuff.
  131. */
  132. void rcvStuff(char reversed)
  133.   {
  134.   label     tempNm;
  135.   struct cmd_data cmds;
  136.   PosId = (callSlot == ERROR) ? FALSE : (netBuf.OurPwd[0] == 0 || (reversed && netBuf.nbflags.Stadel));
  137.   RouteMailForHere = FALSE;
  138.   do
  139.     {
  140.     getNextCommand(&cmds);
  141.     switch (cmds.command)
  142.       {
  143.       case HANGUP:          break;
  144.       case NORMAL_MAIL:    getMail();     break;
  145.       case A_FILE_REQ:
  146.       case R_FILE_REQ:     netFileReq(&cmds);   break;
  147.       case NET_ROOM:       netRRReq(&cmds, FALSE);  break;
  148.       case ROLE_REVERSAL:  reqReversal(reversed);   break;
  149.       case CHECK_MAIL:     reqCheckMail();    break;
  150.       case SEND_FILE:      reqSendFile(&cmds);    break;
  151.       case NET_ROUTE_ROOM: netRRReq(&cmds, TRUE);   break;
  152.       case SYS_NET_PWD:    netPwd(&cmds);     break;
  153.       case ITL_PROTOCOL:   ITL_rec_optimize(&cmds);       break;
  154.       case ITL_COMPACT:    ITL_RecCompact(&cmds);   break;
  155.       case ROUTE_MAIL:     netRouteMail(&cmds);   break;
  156.       case FAST_MSGS:  netFastTran(&cmds);    break;
  157.       default:
  158.       sprintf(tempNm, "'%d' unknown.", cmds.command);
  159.       reply(BAD, tempNm);   break;
  160.  
  161.       }
  162.  
  163.     }
  164.   while (gotCarrier() && cmds.command != HANGUP);
  165.  
  166.   }
  167. /*
  168. * netPwd()
  169. *
  170. * Check out the password sent to us, set flags appropriately.
  171. */
  172. void netPwd(struct cmd_data *cmds)
  173.   {
  174.   if (callSlot != ERROR)
  175.     {
  176.     PosId = !strCmpU(cmds->fields[0], netBuf.OurPwd);
  177.     if (!PosId)
  178.       {
  179.       if( logNetResults )splitF(netLog, "Bad pwd: -%s-\n", cmds->fields[0]);
  180.       sPrintf(msgBuf.mbtext, "%s sent bad password -%s-.",
  181.       callerName, cmds->fields[0]);
  182.       netResult(msgBuf.mbtext);
  183.  
  184.       }
  185.  
  186.     }
  187.   reply(GOOD, "");
  188.  
  189.   }
  190. /*
  191. * doResults()
  192. *
  193. * This function processes the results of receiving thingies and such.
  194. */
  195. void doResults()
  196.   {
  197.   extern SListBase DomainMap;
  198.   void HandleExistingDomain();
  199.   int i;
  200.   label temp;
  201.   extern int RMcount;
  202.   DisableModem(TRUE);
  203.   InitVortexing();    /* handles all mail for here */
  204.   if (processMail)
  205.     {
  206.     if (AddNetMsgs("tempmail.$$$", inMail, 2, MAILROOM, TRUE) == ERROR)
  207.     no_good("No mail file for %s?", TRUE);
  208.  
  209.     }
  210.   if (RouteMailForHere)
  211.     {
  212.     for (i = 0; ; i++)
  213.       {
  214.       sPrintf(temp, "rmail.%d", i);
  215.       if (AddNetMsgs(temp, inRouteMail, 2, MAILROOM, TRUE) == ERROR)
  216.       break;
  217.  
  218.       }
  219.     RMcount = 0;
  220.  
  221.     }
  222.   FinVortexing();   /* finish handling mail */
  223.   if (callSlot == ERROR)
  224.     {
  225.     /* If didn't know this node, don't      */
  226.     EnableModem(TRUE);
  227.     return ;  /* bother with anything else  */
  228.  
  229.     }
  230.   if (checkNegMail) readNegMail(TRUE);
  231.   ReadFastFiles();    /* messages transferred in one big arc */
  232.   doNetRooms();
  233.   AdjustRoute();
  234.   netBuf.nbLastConnect = CurAbsolute();
  235.   putNet(thisNet, &netBuf);
  236.   UpdVirtStuff(); /* Just in case. */
  237.   RunList(&DomainMap, HandleExistingDomain);
  238.   RationalizeDomains(); /* again just in case ... */
  239.   EnableModem(TRUE);
  240.  
  241.   }
  242. /*
  243. * getId()
  244. *
  245. * This gets nodeId and nodeName from caller.
  246. */
  247. void getId()
  248.   {
  249.   char *secRunner;
  250.   #ifdef NEED_THIS_DATA
  251.   SYS_FILE fn;
  252.   #endif
  253.   int i;
  254.   extern long byteRate;
  255.   extern char *APPEND_ANY;
  256.   if (!haveCarrier) return;
  257.   ITL_Receive(NULL, FALSE, TRUE, putFLChar, fclose);
  258.   if (!gotCarrier())
  259.     {
  260.     return ;
  261.  
  262.     }
  263.   strncpy(callerId, RecBuf, NAMESIZE - 1);
  264.   secRunner = RecBuf;
  265.   while (*secRunner != 0) secRunner++;
  266.   secRunner++;
  267.   strncpy(callerName, secRunner, NAMESIZE - 1);
  268.   normId(callerId, normed);
  269.   if (strLen(callerName) == 0 || strLen(callerId) == 0)
  270.     {
  271.     if( logNetResults )splitF(netLog, "getId invalid data, dropping connection.\n\n");
  272.     killConnection();
  273.     #ifdef NEED_THIS_DATA
  274.     makeSysName(fn, "getid.sys", &cfg.netArea);
  275.     if ((upfd = safeopen(fn, APPEND_ANY)) != NULL)
  276.       {
  277.       fwrite(RecBuf, SECTSIZE, 1, upfd);
  278.       fclose(upfd);
  279.  
  280.       }
  281.     #endif
  282.  
  283.     }
  284.   if ((callSlot = searchNet(normed, &netBuf)) == ERROR)
  285.     {
  286.     sPrintf(msgBuf.mbtext, "New caller: %s (%s)", callerName, callerId);
  287.     netResult(msgBuf.mbtext);
  288.  
  289.     }
  290.   else
  291.     {
  292.     for (i = 0; i < SHARED_ROOMS; i++)
  293.     resetNeedsProcessing(i);
  294.     putNet(callSlot, &netBuf);
  295.  
  296.     }
  297.   if( logNetResults)splitF(netLog, "%s (%s) @ %ld\n", callerName, callerId, byteRate * 10L);
  298.  
  299.   }
  300. /*
  301. * getNextCommand()
  302. *
  303. * This gets next command (facility request) from the caller.
  304. */
  305. void getNextCommand(struct cmd_data *cmds)
  306.   {
  307.   zero_struct(*cmds);
  308.   ITL_Receive(NULL, FALSE, TRUE, putFLChar, fclose);
  309.   if (!gotCarrier())
  310.     {
  311.     return ;
  312.  
  313.     }
  314.   grabCommand(cmds, RecBuf);
  315.   }
  316. /*
  317. * grabCommand()
  318. *
  319. * This pulls network cmds out of the specified buffer.
  320. */
  321. void grabCommand(struct cmd_data *cmds, char *sect)
  322.   {
  323.   int fcount = 0;
  324.   cmds->command = sect[0];
  325.   sect++;
  326.   while (sect[0] > 0 && fcount < 4)
  327.     {
  328.     strncpy(cmds->fields[fcount], sect, NAMESIZE - 1);
  329.     cmds->fields[fcount][NAMESIZE - 1] = 0;
  330.     fcount++;
  331.     while (*sect != 0) sect++;
  332.     sect++;
  333.  
  334.     }
  335.   if (cfg.BoolFlags.debug)
  336.     {
  337.     splitF(netLog, "Recieved Command: %d\n", cmds->command);
  338.     splitF(netLog, " Field[0]: %s\n", cmds->fields[0]);
  339.     splitF(netLog, " Field[1]: %s\n", cmds->fields[1]);
  340.     splitF(netLog, " Field[1]: %s\n", cmds->fields[2]);
  341.     splitF(netLog, " Field[2]: %s\n", cmds->fields[3]);
  342.     }
  343.   }
  344. /*
  345. * reply()
  346. *
  347. * This sends a full reply to the caller's request.
  348. */
  349. void reply(char state, char *reason)
  350.   {
  351.   if (!ITL_Send(STARTUP))
  352.     {
  353.     no_good("Couldn't send reply to %s!", TRUE);
  354.     return;
  355.  
  356.     }
  357.   sendITLchar(state);
  358.   if (state == BAD)
  359.     {
  360.     mTrPrintf("%s", reason);
  361.     if (cfg.BoolFlags.debug) splitF(netLog, "Replying BAD: %s\n", reason);
  362.  
  363.     }
  364.   sendITLchar(0);
  365.   ITL_Send(FINISH);
  366.  
  367.   }
  368. /*
  369. * reqReversal()
  370. *
  371. * This handles the role reversal command.
  372. */
  373. void reqReversal(char reversed)
  374.   {
  375.   if ( netDebug ) splitF(netLog, "Role reversal\n");
  376.   if (reversed)
  377.     {
  378.     reply(BAD, "Synch error on Reversal!");
  379.     return ;
  380.  
  381.     }
  382.   reply(GOOD, "");
  383.   if (callSlot == ERROR)      /* Forces a "null" role reversal  */
  384.   zero_struct(netBuf.nbflags);
  385.   sendStuff(TRUE, PosId);
  386.  
  387.   }
  388. /*
  389. * reqCheckMail()
  390. *
  391. * This checks incoming mail and does negative acks where appropriate.
  392. */
  393. void reqCheckMail()
  394.   {
  395.   if( logNetResults && netDebug )splitF(netLog, "checking Mail\n");
  396.   if (!processMail)
  397.     {
  398.     reply(BAD, "No mail to check!");
  399.     return ;
  400.  
  401.     }
  402.   reply(GOOD, "");
  403.   if (ITL_Send(STARTUP))
  404.     {
  405.     AddNetMsgs("tempmail.$$$", targetCheck, FALSE, MAILROOM, TRUE);
  406.     sendITLchar(NO_ERROR);
  407.     ITL_Send(FINISH);
  408.  
  409.     }
  410.  
  411.   }
  412. /*
  413. * targetCheck()
  414. *
  415. * This checks for existence of recipients.
  416. */
  417. void targetCheck()
  418.   {
  419.   if (HasOverrides(&msgBuf))
  420.     {
  421.     RunList(&msgBuf.mbOverride, CheckRecipient);
  422.  
  423.     }
  424.   else
  425.     {
  426.     CheckRecipient(msgBuf.mbto);
  427.  
  428.     }
  429.  
  430.   }
  431. /*
  432. * CheckRecipient()
  433. *
  434. * This will check to see if the recipient exists.
  435. */
  436. void CheckRecipient(char *d)
  437.   {
  438.   char     sigChar;
  439.   if (!d[0])
  440.     {
  441.     sigChar = BAD_FORM;
  442.  
  443.     }
  444.   else if (strchr(d, '!') != NULL)
  445.   return ;  /* STadel routed mail - don't try to check it here */
  446.   else
  447.     {
  448.     if (PersonExists(d) != ERROR)
  449.     return ;
  450.     else
  451.     sigChar = NO_RECIPIENT;
  452.  
  453.     }
  454.   sendITLchar(sigChar);
  455.   mTrPrintf("%s", msgBuf.mbauth);
  456.   mTrPrintf("%s", d);
  457.   mTrPrintf("%s @ %s", msgBuf.mbdate, msgBuf.mbtime);
  458.  
  459.   }
  460. /*
  461. * doNetRooms()
  462. *
  463. * This function integrates temporary files containing incoming messages into
  464. * the data base.
  465. */
  466. void doNetRooms()
  467.   {
  468.   SYS_FILE fileNm;
  469.   int IntegrateRoom(SharedRoom *room, int system, int index, int roomslot,
  470.   void *d);
  471.   EachSharedRoom(thisNet, IntegrateRoom, NULL, NULL);
  472.   makeSysName(fileNm, RECOVERY_FILE, &cfg.netArea);
  473.   unlink(fileNm);
  474.  
  475.   }
  476. /*
  477. * IntegrateRoom()
  478. *
  479. * This function helps integrate incoming messages into a room.
  480. */
  481. int IntegrateRoom(SharedRoom *room, int system, int index, int roomslot,
  482. void *d)
  483.   {
  484.   if (chkNeedsProcessing(index))
  485.     {
  486.     ReadNetRoomFile(index, NULL);
  487.     resetNeedsProcessing(index);
  488.  
  489.     }
  490.   if (SR_Sent[index] == 1)
  491.   netBuf.netRooms[index].lastMess =
  492.   roomTab[roomslot].rtlastMessage;
  493.   return TRUE;
  494.  
  495.   }
  496. /*
  497. * ReadNetRoomFile()
  498. *
  499. * This function reads in a file of messages received on net.
  500. * NB: the passed parameter is the index into the netBuf.netRooms
  501. * pseudo-array, not the number of the room itself.  See the code.
  502. */
  503. void ReadNetRoomFile(int rover, char *fn)
  504.   {
  505.   label temp2;
  506.   if (fn == NULL) sPrintf(temp2, netRoomTemplate, netRoomSlot(rover));
  507.   getRoom(netRoomSlot(rover));
  508.   if (roomBuf.rbShareType != PEON &&
  509.   GetMode(netBuf.netRooms[rover].mode) != PEON)
  510.   AssignAddress = NON_LOC_NET;
  511.   else
  512.   AssignAddress = LOC_NET;
  513.   InitVortexing();
  514.   AddNetMsgs((fn == NULL) ? temp2 : fn, inMail, TRUE, netRoomSlot(rover),
  515.   (fn == NULL));
  516.   FinVortexing();
  517.   AssignAddress = NULL;
  518.  
  519.   }
  520. /*
  521. * getMail()
  522. *
  523. * This function Grabs mail from caller.
  524. */
  525. void getMail()
  526.   {
  527.   SYS_FILE tempNm;
  528.   if( netDebug && logNetResults) splitF(netLog, "Receiving Mail\n");
  529.   makeSysName(tempNm, "tempmail.$$$", &cfg.netArea);
  530.   if (ITL_StartRecMsgs(tempNm, TRUE, TRUE, NULL) == ITL_SUCCESS)
  531.     {
  532.     processMail = TRUE;
  533.  
  534.     }
  535.  
  536.   }
  537. /*
  538. * reqSendFile()
  539. *
  540. * This function handles receiving a sent file.  Note that it handles file
  541. * redirection.
  542. */
  543. void reqSendFile(struct cmd_data *cmds)
  544.   {
  545.   long  proposed;
  546.   int count;
  547.   char work[100], work1[100], *Dir;
  548.   extern char *READ_ANY, *WRITE_ANY;
  549.   static char *Reject = "File %s from %s rejected because %s.";
  550.   /* don't accept files from rogues */
  551.   if (!PosId)
  552.     {
  553.     reply(BAD, "No room for file.");
  554.     return;
  555.  
  556.     }
  557.   /* handle incoming file redirection */
  558.   if ((Dir = RedirectFile(cmds->fields[0], netBuf.netName)) != NULL ||
  559.   (Dir = RedirectFile(cmds->fields[0], netBuf.nbShort)) != NULL)
  560.     {
  561.     RedirectName(work1, Dir, "mm12"); /* temp file name */
  562.     unlink(work1);  /* kill any prior backups (shouldn't be any ...) */
  563.     RedirectName(work, Dir, cmds->fields[0]);
  564.     if (access(work, 0) == 0)
  565.     rename(work, work1);
  566.  
  567.     }
  568.   else if (netSetNewArea(&cfg.receptArea))
  569.     {
  570.     proposed = atol(cmds->fields[2]);
  571.     if (sysRoomLeft() < proposed ||
  572.     proposed > ((long) cfg.maxFileSize) * 1024l)
  573.       {
  574.       reply(BAD, "No room for file.");
  575.       sPrintf(msgBuf.mbtext, Reject, cmds->fields[0], callerName,
  576.       proposed > ((long) cfg.maxFileSize) * 1024l ?
  577.       "the file was larger than #MAX_NET_FILE" :
  578.       "there was not enough room left in reception directory");
  579.       netResult(msgBuf.mbtext);
  580.       homeSpace();
  581.       return;
  582.  
  583.       }
  584.     count = 0;
  585.     strCpy(work, cmds->fields[0]);
  586.     while (access(work, 0) != -1)
  587.       {
  588.       sPrintf(work, "a.%d", count++);
  589.  
  590.       }
  591.  
  592.     }
  593.   else
  594.     {
  595.     reply(BAD, "System error");
  596.     return ;
  597.  
  598.     }
  599.   reply(GOOD, NULL);
  600.   if( logNetResults )splitF(netLog, "File Reception: %s\n", cmds->fields[0]);
  601.   ITL_Receive(work, FALSE, TRUE, putFLChar, fclose);
  602.   homeSpace();
  603.   if (haveCarrier)
  604.     {
  605.     if (strCmp(work, cmds->fields[0]) == SAMESTRING || Dir != NULL)
  606.     sPrintf(msgBuf.mbtext, "%s received from %s.", cmds->fields[0],
  607.     callerName);
  608.     else
  609.     sPrintf(msgBuf.mbtext, "%s (saved as %s) received from %s.",
  610.     cmds->fields[0], work, callerName);
  611.     netResult(msgBuf.mbtext);
  612.     if (Dir != NULL)  /* kill temporary bkp of redirected file */
  613.     unlink(work1);
  614.  
  615.     }
  616.   else if (Dir != NULL) /* failed transfer of redirected file */
  617.   rename(work1, work);
  618.  
  619.   }
  620. /*
  621. * netFileReq()
  622. *
  623. * This will handle requests for file transfers.
  624. */
  625. void netFileReq(struct cmd_data *cmds)
  626.   {
  627.   int  roomSlot;
  628.   extern char *READ_ANY;
  629.   if( logNetResults)splitF(netLog, "File request: %s in %s\n", cmds->fields[1],
  630.   cmds->fields[0]);
  631.   /* allow disabling this feature on a system by system basis */
  632.   if (PosId && netBuf.nbflags.NoDL)
  633.     {
  634.     reply(BAD, "Downloading disabled.");
  635.     return;
  636.  
  637.     }
  638.   if ((roomSlot = roomExists(cmds->fields[0])) == ERROR   ||
  639.   !roomTab[roomSlot].rtflags.ISDIR  ||
  640.   roomTab[roomSlot].rtflags.NO_NET_DOWNLOAD ||
  641.   !roomTab[roomSlot].rtflags.DOWNLOAD)
  642.     {
  643.     sPrintf(msgBuf.mbtext, "Room %s does not exist.", cmds->fields[0]);
  644.     reply(BAD, msgBuf.mbtext);
  645.     return;
  646.  
  647.     }
  648.   getRoom(roomSlot);
  649.   if (!setSpace(&roomBuf))
  650.     {
  651.     reply(BAD, "Directory error");
  652.     return;
  653.  
  654.     }
  655.   if (cmds->command == A_FILE_REQ)
  656.     {
  657.     reply(GOOD, "");
  658.     sPrintf(msgBuf.mbtext, "Following files sent to %s from %s: ",
  659.     callerName, roomBuf.rbname);
  660.     wildCard(netMultiSend, cmds->fields[1], FALSE, "", FALSE);
  661.     if (ITL_Send(STARTUP))
  662.       {
  663.       mTrPrintf("");
  664.       ITL_Send(FINISH);
  665.  
  666.       }
  667.  
  668.     }
  669.   else
  670.     {
  671.     if (access(cmds->fields[1], 4) == -1)
  672.       {
  673.       sPrintf(msgBuf.mbtext, "There is no '%s' in %s.", cmds->fields[1],
  674.       cmds->fields[0]);
  675.       reply(BAD, msgBuf.mbtext);
  676.       homeSpace();
  677.       return;
  678.  
  679.       }
  680.     reply(GOOD, "");
  681.     SendHostFile(cmds->fields[1]);
  682.     sPrintf(msgBuf.mbtext,
  683.     "%s downloaded from %s by %s.",
  684.     cmds->fields[1], formRoom(thisRoom, FALSE, FALSE), callerName);
  685.  
  686.     }
  687.   homeSpace();
  688.   netResult(msgBuf.mbtext);
  689.  
  690.   }
  691. /*
  692. * netRRReq()
  693. *
  694. * This function handles room sharing.  If SendBack is TRUE then this is a
  695. * room routing (LD) request and requires we send the room's current contents
  696. * back.
  697. */
  698. void netRRReq(struct cmd_data *cmds, char SendBack)
  699.   {
  700.   RoomSearch arg;
  701.   char reason[50];
  702.   strCpy(arg.Room, cmds->fields[0]);
  703.   if (!RoomRoutable(&arg))
  704.     {
  705.     sPrintf(reason, SharingRefusal[arg.reason], cmds->fields[0]);
  706.     if( logNetResults )splitF(netLog, "Refusing to share %s (%s)\n", cmds->fields[0], reason);
  707.     reply(BAD, reason);
  708.     return;
  709.  
  710.     }
  711.   if (!arg.virtual)
  712.     {
  713.     getRoom(arg.room);
  714.     recNetMessages(arg.index, arg.Room, arg.room, TRUE);
  715.     if (SendBack)
  716.     findAndSend(ERROR, R_SH_MARK, LOC_NET,
  717.     roomBuf.rbShareType == BACKBONE ? NON_LOC_NET : NULL, arg.index,
  718.     RoomSend, roomBuf.rbname, RoomReceive);
  719.  
  720.     }
  721.   else
  722.     {
  723.     RecVirtualRoom(arg.index, TRUE);
  724.     if (SendBack)
  725.     findAndSend(ERROR, NULL, NULL, NULL, arg.index, SendVirtual,
  726.     arg.Room, RecVirtualRoom);
  727.  
  728.     }
  729.  
  730.   }
  731. /*
  732. * recNetMessages()
  733. *
  734. * This function receives net messages.  This is not the same as processing
  735. * them.
  736. */
  737. void recNetMessages(int arraySlot, char *name, int slot, char ReplyFirst)
  738.   {
  739.   SYS_FILE fileNm, temp;
  740.   char reason[60];
  741.   if( netDebug )splitF(netLog, "Receiving %s\n", name);
  742.   sPrintf(temp, netRoomTemplate, slot);
  743.   makeSysName(fileNm, temp, &cfg.netArea);
  744.   switch (ITL_StartRecMsgs(fileNm, ReplyFirst, TRUE, NULL))
  745.     {
  746.     case ITL_SUCCESS:
  747.     setNeedsProcessing(arraySlot);
  748.     UpdateRecoveryFile(name);
  749.     break;
  750.     case ITL_NO_OPEN:
  751.     sPrintf(reason, "Internal error for %s", name);
  752.     reply(BAD, reason);
  753.     break;
  754.     case ITL_BAD_TRANS:
  755.     break;
  756.  
  757.     }
  758.  
  759.   }
  760. /*
  761. * UpdateRecoveryFile()
  762. *
  763. * This function updates the network recovery file.
  764. */
  765. void UpdateRecoveryFile(char *val)
  766.   {
  767.   SYS_FILE fileNm;
  768.   makeSysName(fileNm, RECOVERY_FILE, &cfg.netArea);
  769.   if (access(fileNm, 0) != 0)
  770.   CallMsg(fileNm, callerId);
  771.   CallMsg(fileNm, val);
  772.  
  773.   }
  774. /*
  775. * RoomRoutable()
  776. *
  777. * Is this room routable?
  778. */
  779. char RoomRoutable(RoomSearch *data)
  780.   {
  781.   if (!PosId)
  782.     {
  783.     data->reason = NO_PWD;
  784.     return FALSE;
  785.  
  786.     }
  787.   if (callSlot == ERROR)
  788.     {
  789.     data->reason = NOT_SHARING;
  790.     return FALSE;
  791.  
  792.     }
  793.   data->reason = NO_ROOM;
  794.   data->virtual = FALSE;
  795.   EachSharedRoom(thisNet, IsRoomRoutable, VirtRoomRoutable, data);
  796.   return (char)(data->reason == FOUND);
  797.  
  798.   }
  799. /*
  800. * IsRoomRoutable()
  801. *
  802. * This function checks to see if the given shared room matches with the
  803. * argument presented in the void pointer parameter.
  804. */
  805. int IsRoomRoutable(SharedRoom *room, int system, int index, int roomslot,
  806. void *d)
  807.   {
  808.   RoomSearch *arg;
  809.   arg = d;
  810.   if (strCmpU(roomTab[roomslot].rtname, arg->Room) == SAMESTRING)
  811.     {
  812.     if (roomTab[roomslot].rtflags.SHARED == 0)
  813.     arg->reason = NOT_SHARING;
  814.     else
  815.     arg->reason = FOUND;
  816.     arg->room = roomslot;
  817.     arg->index = index;
  818.     return ERROR;   /* stop searching */
  819.  
  820.     }
  821.   return TRUE;
  822.  
  823.   }
  824. /*
  825. * netMultiSend()
  826. *
  827. * This function will send requested files via the net.
  828. */
  829. void netMultiSend(DirEntry *fn)
  830.   {
  831.   long Sectors;
  832.   if (!gotCarrier()) return ;
  833.   strCat(msgBuf.mbtext, fn->unambig);
  834.   strCat(msgBuf.mbtext, " ");
  835.   Sectors     = ((fn->FileSize + 127) / SECTSIZE);
  836.   if (ITL_Send(STARTUP))
  837.     {
  838.     mTrPrintf("%s", fn->unambig);
  839.     mTrPrintf("%ld", Sectors);
  840.     ITL_Send(FINISH);
  841.  
  842.     }
  843.   SendHostFile(fn->unambig);
  844.  
  845.   }
  846. /*
  847. * RecoverNetwork()
  848. *
  849. * This function is called during system startup.  If a disaster hit during
  850. * a network session, this will try to recover messages already transferred
  851. * from files left in the network directory.
  852. */
  853. void RecoverNetwork()
  854.   {
  855.   SYS_FILE fileNm;
  856.   char line[50];
  857.   label temp;
  858.   int rover;
  859.   FILE *fd;
  860.   RoomSearch arg;
  861.   extern char inNet;
  862.   makeSysName(fileNm, RECOVERY_FILE, &cfg.netArea);
  863.   if ((fd = safeopen(fileNm, READ_TEXT)) == NULL)
  864.   return;   /* normal */
  865.   inNet = NORMAL_NET;
  866.   SpecialMessage("Network Cleanup");
  867.   if (GetAString(line, sizeof line, fd) != NULL)
  868.     {
  869.     if (searchNet(line, &netBuf) != ERROR)
  870.       {
  871.       PosId = TRUE;
  872.       while (GetAString(line, sizeof line, fd) != NULL)
  873.         {
  874.         if (strncmp(line, FAST_TRANS_FILE, strLen(FAST_TRANS_FILE))
  875.         == SAMESTRING)
  876.         RecoverMassTransfer(line);
  877.         else
  878.           {
  879.           strCpy(arg.Room, line);
  880.           if (RoomRoutable(&arg) && !arg.virtual)
  881.             {
  882.             printf("%s\n", line);
  883.             ReadNetRoomFile(arg.index, NULL);
  884.  
  885.             }
  886.  
  887.           }
  888.  
  889.         }
  890.       readNegMail(FALSE);
  891.       AddNetMsgs("tempmail.$$$", inMail, 2, MAILROOM, TRUE);
  892.       for (rover = 0; ; rover++)
  893.         {
  894.         sPrintf(temp, "rmail.%d", rover);
  895.         if (AddNetMsgs(temp, inRouteMail, 2, MAILROOM, TRUE) == ERROR)
  896.         break;
  897.  
  898.         }
  899.  
  900.       }
  901.  
  902.     }
  903.   fclose(fd);
  904.   unlink(fileNm);
  905.   inNet = NON_NET;
  906.  
  907.   }
  908.